package com.code.day15;

public class DieLock implements Runnable {
    private boolean flag;

    public DieLock(boolean flag) {
        this.flag = flag;
    }

    @Override
    public void run() {
        if (flag) {
            synchronized (LockA.lockA) {
                System.out.println("A线程开始执行");
                synchronized (LockB.lockB) {
                    System.out.println("B线程开始执行");
                }
            }
        } else {
            synchronized (LockB.lockB) {
                System.out.println("B线程开始执行");
                synchronized (LockA.lockA) {
                    System.out.println("A线程开始执行");
                }
            }
        }

    }
}
